<?php
/**
 * 全站搜索 列表文件
 *
 * @author		Arthur(ArthurXF@gmail.com)
 * @copyright	(c) 2006 by bizeway.com
 * @version		$Id$
 * @package		ArthurXF
 * @subpackage	product
 */
require_once('config/config.inc.php');
require_once("class/product.class.php");

$objWebInit = new product();
//数据库连接参数
$objWebInit->setDBG($arrGPdoDB);
//smarty参数
$arrGSmarty['caching'] = false;
$objWebInit->arrGSmarty = $arrGSmarty;
//翻页参数
$objWebInit->arrGPage = $arrGPage;
//图片参数
$objWebInit->arrGPic = $arrGPic;
$objWebInit->db();

$arrWhere = array();
$arrLink = array();

if (empty($_GET['page'])) {
	$intPage = 1 ;
} else {
	$intPage = intval($_GET['page']);
}

if(!empty($_REQUEST['keywords'])){
	$strKeywords = strval(urldecode($_REQUEST['keywords']));
	if($strKeywords[0] == '/'){
		//精确查询ID
		$strKeywords = substr($strKeywords,1);
		if(is_numeric($strKeywords)) $arrWhere[] = "id = '" . $strKeywords . "'";
	}else{
		$arrKeywords = explode(' ', $strKeywords);
		foreach($arrKeywords as $v){
			$v = trim($v);
			if(!empty($v)){
				if (isset($_GET['radio'])){
					$intTemp = intval($_GET['radio']);
					switch($intTemp){
						case 0:
							$arrWhere[] = "brand LIKE '%$v%'";
							$arrWhere[] = "model LIKE '%$v%'";
							$arrWhere[] = "code LIKE '%$v%'";
							$arrWhere[] = "title LIKE '%$v%'";
							break;
						case 1:
							$arrWhere[] = "brand LIKE '%$v%'";
							break;
						case 2:
							$arrWhere[] = "model LIKE '%$v%'";
							break;
						case 3:
							$arrWhere[] = "code LIKE '%$v%'";
							break;
						case 4:
							$arrWhere[] = "title LIKE '%$v%'";
							break;
					}
					$arrLink[] = 'radio=' . $intTemp;

				}else $arrWhere[] = "title LIKE '%$v%'";
			}
		}
	}
	$arrLink[] = 'keywords=' . urlencode($strKeywords);
}else check::AlertExit("错误：关键词必须填写!",-1);


$strWhere = '';
$strWhere = implode(' or ',$arrWhere);
$strWhere = 'where pass=1 and '.$strWhere;
$arrInfoList = $objWebInit->getInfoList($strWhere, ' ORDER BY submit_date DESC',($intPage-1)*$arrGPage['page_size'],$arrGPage['page_size'],true);
$intRows = $arrInfoList['COUNT_ROWS'];
unset($arrInfoList['COUNT_ROWS']);

//静态url处理
$strLink = '';
if($arrGWeb['URL_static']){
	if (!empty($arrLink)) $strLink = str_replace('=','-',implode('-',$arrLink));
}else{
	if (!empty($arrLink)) $strLink = implode('&',$arrLink);
}

//翻页跳转link
$strPage= $objWebInit->makeInfoListPage($intRows,$strLink,$link_type=$arrGWeb['URL_static']);

include '../product/block/_menu.php';
$arrMOutput["smarty_assign"]['strBlock1'] = "product/block/_menu.html";
include '../brand/block/top.php';
$arrMOutput["smarty_assign"]['strBlock2'] = "brand/block/top.html";

//站内搜索关键词统计
include '../keywords/block/save.php';
//全站公用block
include '../_block.php';


// 输出到模板
$arrMOutput["smarty_assign"]['arrInfoList'] = $arrInfoList;
$arrMOutput["smarty_assign"]['strPage'] = $strPage;
$arrMOutput["smarty_assign"]['page'] = $intPage;
$arrMOutput["smarty_assign"]['keywordslink'] = '&keywords=' . urlencode($strKeywords);
$arrMOutput["smarty_assign"]['arrMType'] = $arrMType;
$arrMOutput["smarty_assign"]['strTypeTitle'] = $strKeywords."搜索结果";
$arrMOutput['smarty_assign']['Title'] = $strKeywords.'搜索结果 - '.$arrGWeb['name'];
$arrMOutput['smarty_assign']['Description'] = $strKeywords.'搜索结果 - '.$arrGWeb['name'];
$arrMOutput['smarty_assign']['Keywords'] = $strKeywords.'搜索结果 - '.$arrGWeb['name'];
$arrMOutput["smarty_assign"]['FileCallPath'] = $objWebInit->arrGPic['FileCallPath'];
$arrMOutput["smarty_assign"]['MAIN'] = $arrGSmarty['main_dir'].'search.html';
$objWebInit->output($arrMOutput);
?>